from pathlib import Path

import requests


def psider_bing():

    json_data = requests.get(url='https://cn.bing.com/hp/api/model?mkt=zh-CN').json()
    pic_url = 'https://s.cn.bing.net' + json_data['MediaContents'][0]['ImageContent']['Image']['Wallpaper']
    print(pic_url)

    img_data = requests.get(pic_url).content

    """ linux服务器,  windows服务器 """
    # 获取当前项目的根目录
    BASE_DIR = Path(__file__).resolve().parent.parent

    with open(BASE_DIR.joinpath('app/blog/static/imgs/bing.jpg'), mode='wb') as f:
        f.write(img_data)

